<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
 <body bgcolor="#C0C0C0">
<?php
$connection = @mysql_connect('phpmyadmin.hosting.we.po.opole.pl', 'debesciak', 'informatyka1') 
or die('Brak połączenia z serwerem MySQL.<br />Błąd: '.mysql_error()); 


$db = @mysql_select_db('stelmach', $connection) 
or die('Brak polaczenia z bazą danych<br />Błąd: '.mysql_error()); 
 
$zapytanie = "SET charset utf8";
if(isset($_POST['form1'])) {
echo "<br /><br />";
$id_ar=$_POST['id_a'];
$zapytanie4 = "SELECT ID_ARTYKULU, TYTUL, TRESC, AUTOR FROM artykuly WHERE ID_ARTYKULU='$id_ar'";;
$wykonaj2 = mysql_query($zapytanie4);
$znaleziono2 = mysql_num_rows($wykonaj2);
while ($row = mysql_fetch_array($wykonaj2))  {
$tresciowo=$row['TRESC'];
$tytul=$row['TYTUL'];
$autor=$row['AUTOR'];
echo"<h1><center>$tytul</center></h1>";
echo"<p align='justify'>$tresciowo</p>";
echo"<br><p align='right'>$autor</p>";
}
}?>


<?php
function cutString($trescik,$end) {
if(strlen($trescik)>$end){
$trescik=preg_replace('/s+?(S+)?$/','',substr($trescik,0,$end+1));
$trescik=substr($trescik,0,$end)."...";
}
return $trescik;
}
echo "<br /><br />";
$zapytanie4 = "SELECT ID_ARTYKULU, TYTUL, TRESC, AUTOR FROM artykuly";;
$wykonaj2 = mysql_query($zapytanie4);
$znaleziono2 = mysql_num_rows($wykonaj2);
if ($znaleziono2 == "0")  {
  print "There is no articles to read";
}
?>
<table border="1" align="center">
<tr>
		<th style="height: 28px; text-transform:uppercase;">ID</th>
		<th style="height: 28px; text-transform:uppercase;">Title</th>	
		<th style="height: 28px; text-transform:uppercase;">Content</th>	
		<th style="height: 28px; text-transform:uppercase;">Author</th>					
</tr>
<?php
while ($row = mysql_fetch_array($wykonaj2))  {
$tresc=$row['TRESC'];
$obciety= cutString($tresc,'50');
 echo "<tr><td>".$row['ID_ARTYKULU']."</td><td>".$row['TYTUL']."</td><td>".$obciety."</td><td>".$row['AUTOR']."</td></tr>";
}
echo "</table>";

echo "<br /><br />";

?>


<form style="background-color:#C0C0C0" method=post>
<input type="hidden" name="form1" value="10">
<h1>Choose the article to read</h1>
<br />
<h2> Fill the form</h2>
<table border=0>
<tr><td style="height: 48px">ID ARTICLE:</td><td style="height: 48px"><textarea name="id_a"></textarea></td></tr>

<tr><td colspan=2><input type=submit name="submit2" value='OPEN'></td></tr></table>
</form>









</body>
</html>